let a = 1,b = 2,c = 3;

let arr = [1,2,3];
let [a1,a2,a3,a4] = arr;

console.log("a1 = ",a1);
console.log("a2 = ",a2);
console.log("a3 = ",a3);
console.log("a4 = ",a4);

// 解构赋值（FireFox、谷歌浏览器上会报错）
// 非标准语法
[a1,a2,a3,a4] = ['a','b','c','d'];
console.log("a1 = ",a1);
console.log("a2 = ",a2);
console.log("a3 = ",a3);
console.log("a4 = ",a4);

let [b1,[,b2],b3] = [1,[2,3],4];
console.log("b2 =",b2); // 3

// rest参数：rest参数只能出现在最后，rest参数会以数组方式接收参数
let [c1,...c2] = [1,2,3,4];
console.log("c2 = ",c2); // [2,3,4]

function sum(...b) {
    // console.log("a = ",a);
    console.log("b = ",b);
}

sum(1,2);
sum(1,2,3);
sum(1,2,3,4);


let [d1,d2,...d3] = ['a'];
console.log("d1 =",d1); // 'a'
console.log("d2 =",d2); // undefined
console.log("d3 =",d3); // []

let e1 = 100;
let e2 = 200;

// 可以利用解构，快速交换两个变量的值
[e1,e2] = [e2,e1];
console.log("e1 =",e1); // 'a'
console.log("e2 =",e2); // undefined